package com.kaifamiao.define;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.util.logging.Logger;

/**
 * 第一种定义Servlet类的方式:
 * 通过实现 javax.servlet.Servlet 接口 来定义一个 Servlet 类
 */
public class PrimitiveServlet implements Servlet {

    private Logger logger = Logger.getLogger( this.getClass().getName() );

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        logger.info( "初始化" );
    }

    @Override
    public void service(ServletRequest req , ServletResponse resp )
            throws ServletException, IOException {
        logger.info( "服务" );

        resp.setContentType( "text/html" );

        PrintWriter out = resp.getWriter();
        out.println( "<title>PrimitiveServlet</title>" );
        out.println( "<h3>" + LocalDateTime.now() + "</h3>" );
    }

    @Override
    public void destroy() {
        logger.info( "销毁" );
    }

    @Override
    public String getServletInfo() {
        return null;
    }
    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

}
